package com.vikutorika.servlet;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.vikutorika.service.AdminService;
import com.vikutorika.util.ParamUtil;
import com.vikutorika.vo.AdminVo;
import com.vikutorika.vo.ResultVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

@WebServlet("/admin")
public class AdminServlet extends BaseServlet{

	// 测试接口方法
	public void test(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(ResultVo.success("登录成功")));
	}

	// 用户登录
	public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}

	// 分页获取用户信息列表
	public void userList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}

	// 删除用户
	public void userDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}

	// 冻结用户
	public void userFreeze(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}

	// 获取举报信息
	public void complainList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}

	// 删除举报信息
	public void complainDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}

	// 获取反馈信息
	public void feedbackList(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}

	// 添加反馈信息
	public void feedbackAdd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}

	// 删除反馈信息
	public void feedbackDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		AdminVo adminVo = ParamUtil.jsonToBean(req, AdminVo.class);
		System.out.println(adminVo);
		ResultVo resultVo = new AdminService().login(adminVo, req, resp);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(JSONUtil.toJsonStr(resultVo));
	}
}
